package com.system.util;
import com.system.entity.Takecourse;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;


import java.io.File;
import java.util.List;

public class test {
    public static void main(String args[]){
        test t = new test();
        t.InExcel();
    }
    public  void InExcel() {
        try {

            WritableWorkbook wwb = null;
            // 创建可写入的Excel工作簿
            String fileName = "D://book.xls";
            File file=new File(fileName);
            if (!file.exists()) {
                file.createNewFile();
            }
            //以fileName为文件名来创建一个Workbook
            wwb = Workbook.createWorkbook(file);
            // 创建工作表
            WritableSheet ws = wwb.createSheet("用户信息", 0);
            //查询数据库中所有的数据
//            List<Takecourse> list = takeCourseService.findByCourseID(stu_id,course_id);
            //要插入到的Excel表格的行号，默认从0开始
            Label labelId= new Label(0, 0, "学号");//表示第
            Label labelName= new Label(1, 0, "姓名");
            Label labelusualP = new Label(2, 0, "平时分");
            Label labelExperP= new Label(3, 0, "实验分");
            Label labelFinalP= new Label(4, 0, "期末分");
            Label labeltotalP = new Label(5, 0, "总分");
            ws.addCell(labelId);
            ws.addCell(labelName);
            ws.addCell(labelusualP);
            ws.addCell(labelExperP);
            ws.addCell(labelFinalP);
            ws.addCell(labeltotalP);
//            for (int i = 0; i < list.size(); i++) {
//                Label labelId_i= new Label(0, i+1, list.get(i).getStu_id()+"");
//                Label labelName_i= new Label(1, i+1, list.get(i).getStu_name());
//                Label labelUsalP_i= new Label(2, i+1, list.get(i).getUsualPerformance()+"");
//                Label labelExperP_i= new Label(3, i+1, list.get(i).getExperience()+"");
//                Label labelFinalP_i= new Label(4, i+1, list.get(i).getFinalPerformance()+"");
//                Label labelTotalP_i = new Label(5,i+1,list.get(i).getTotalPerformance()+"");
//                ws.addCell(labelId_i);
//                ws.addCell(labelName_i);
//                ws.addCell(labelUsalP_i);
//                ws.addCell(labelExperP_i);
//                ws.addCell(labelFinalP_i);
//                ws.addCell(labelTotalP_i);
//            }
            //写进文档
            wwb.write();
            // 关闭Excel工作簿对象
            wwb.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
